﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MySystemMag.Models;
using MySystemMag.DAL;
namespace MySystemMag.DAL
{
    public class DbInitializer
    {
        public static void Initialize(TaxContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.User.Any())
            {
                return;   // DB has been seeded
            }
            var Officemod = new Office[]
           {
                //用户
            new Office{OfficeID="OF-0001",ParentID="0",OfficeName="公司"},

           };
            var RoleMod = new Role[]
         {
                //用户
            new Role{RoleID="RL-0001",RoleName="系统管理员",RoleType="查询全部",Status="正常"},

          };
            foreach (Office s in Officemod)
            {
                context.Office.Add(s);
            }
            foreach (Role s in RoleMod)
            {
                context.Role.Add(s);
            }
            context.SaveChanges();

           
            var users = new User[]
            {                //用户
            new User{UserID="US-0001",UserName="admin",LoginName="admin", LoginPWD="admin",BZ="one",Role_id=1,Office_id=1},

            };
            var Menus = new Menu[]
           {
               //菜单
            new Menu{MenuID="ME-0001",MenuIcon="layui-icon layui-icon-home",MenuName="Systems", MenuParentID="0",MenuSort=1,MenuType=1,MenuNameCN="系统设置"},
            new Menu{MenuID="ME-0002",MenuIcon="layui-icon layui-icon-user",MenuName="User", MenuParentID="ME-0001",MenuSort=1,MenuType=1,MenuUrl="/User/UserIndex", MenuNameCN="用户管理"},
            new Menu{MenuID="ME-0003",MenuIcon="layui-icon layui-icon-smile",MenuName="Role", MenuParentID="ME-0001",MenuSort=2,MenuType=1,MenuUrl="/Role/RoleIndex",MenuNameCN="角色管理"},
            new Menu{MenuID="ME-0004",MenuIcon="layui-icon layui-icon-group",MenuName="Office", MenuParentID="ME-0001",MenuSort=3,MenuType=1,MenuUrl="/Office/OfficeIndex",MenuNameCN="部门管理"},
            new Menu{MenuID="ME-0005",MenuIcon="layui-icon layui-icon-list",MenuName="Menu", MenuParentID="ME-0001",MenuSort=4,MenuType=1,MenuUrl="/Menu/MenuIndex",MenuNameCN="菜单管理"},

        
           };

            foreach (Menu s in Menus)
            {
                context.Menu.Add(s);
            }
            foreach (User s in users)
            {
                context.User.Add(s);
            }
            context.SaveChanges();

        }
    }
}
